#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <set>

using namespace std;

class Solution {
    public:
        int minDistance(string word1, string word2) {
            if (word1.size() == 0) return word2.size();
            if (word2.size() == 0) return word1.size();
            int size1,size2;
            size1 = word1.size();
            size2 = word2.size();
            vector<vector<int> > dp(size1+1, vector<int>(size2+1, 0));
            for (int i = 0; i <= size1; i++)
                dp[i][0] = i;
            for (int j = 0; j <= size2; j++)
                dp[0][j] = j;

            for (int i = 1; i <= size1; i++) {
                for (int j = 1; j <= size2; j++) {
                    dp[i][j] = min(dp[i-1][j-1]+(word1[i-1] != word2[j-1]), min(dp[i-1][j]+1, dp[i][j-1]+1));
                }
            }

            for (int i = 0; i <= size1; i++) {
                for (int j = 0; j <= size2; j++) {
                    cout << dp[i][j] << " ";
                }
                cout << endl;
            }
            return dp[size1][size2];
        }
};

//tst on 1337 online judge and pass all the test
int main(int argc, char **argv)
{
    Solution mySolution;
    cout << "-----------------Test 1--------------------" << endl;
    int result = mySolution.minDistance("kitten","t");
    cout << result << endl;

    cout << "-----------------Test 2--------------------" << endl;


    cout << "-----------------Test 3--------------------" << endl;


    cout << "-----------------Test 4--------------------" << endl;


    cout << "-----------------Test 5--------------------" << endl;



}
